package com.ruoyi.performancecomparisons.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.performancecomparisons.domain.Series;
import com.ruoyi.performancecomparisons.service.ISeriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * seriesController
 * 
 * @author yxy
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/series/series")
public class SeriesController extends BaseController
{
    @Autowired
    private ISeriesService seriesService;

    /**
     * 查询series列表
     */
    @PreAuthorize("@ss.hasPermi('series:series:list')")
    @GetMapping("/list")
    public TableDataInfo list(Series series)
    {
        startPage();
        List<Series> list = seriesService.selectSeriesList(series);
        return getDataTable(list);
    }

    /**
     * 导出series列表
     */
    @PreAuthorize("@ss.hasPermi('series:series:export')")
    @Log(title = "series", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Series series)
    {
        List<Series> list = seriesService.selectSeriesList(series);
        ExcelUtil<Series> util = new ExcelUtil<Series>(Series.class);
        util.exportExcel(response, list, "series数据");
    }

    /**
     * 获取series详细信息
     */
    @PreAuthorize("@ss.hasPermi('series:series:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(seriesService.selectSeriesById(id));
    }

    /**
     * 新增series
     */
    @PreAuthorize("@ss.hasPermi('series:series:add')")
    @Log(title = "series", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Series series)
    {
        return toAjax(seriesService.insertSeries(series));
    }

    /**
     * 修改series
     */
    @PreAuthorize("@ss.hasPermi('series:series:edit')")
    @Log(title = "series", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Series series)
    {
        return toAjax(seriesService.updateSeries(series));
    }

    /**
     * 删除series
     */
    @PreAuthorize("@ss.hasPermi('series:series:remove')")
    @Log(title = "series", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(seriesService.deleteSeriesByIds(ids));
    }


    /**
     * 根据optionn查询series列表
     */
    @Anonymous
    @GetMapping("/listByOption")
    public List<Series> listByoption(Series series)
    {
        List<Series> list = seriesService.selectSeriesListByoption(series.getOptionn());
        return list;
    }

}
